<template>
  <div class="container">
    <div class="top">
      <el-input
        style="width: 200px; margin-bottom: 5px"
        v-model="search.bank_name"
        clearable
        placeholder="请输入银行名称"
      ></el-input>
      <el-input
        style="width: 200px; margin-bottom: 5px"
        v-model="search.account"
        clearable
        placeholder="请输入卡号"
      ></el-input>
      <el-input
        style="width: 200px; margin-bottom: 5px"
        v-model="search.area"
        clearable
        placeholder="请输入区域"
      ></el-input>
      <el-button
        size="small"
        type="primary"
        class="handleSearch"
        icon="el-icon-search"
        @click="handleSearch()"
        >查询</el-button
      >
      <el-button
        size="small"
        type="danger"
        class="handleSearch"
        icon="el-icon-delete"
        @click="empty()"
        >清空</el-button
      >
      <el-button
        class="add"
        icon="el-icon-circle-plus"
        size="small"
        type="primary"
        @click="addBank"
        >添加银行账号</el-button
      >
    </div>
    <el-table
      max-height="600"
      :data="tableData"
      border
      style="width: 100%"
      empty-text="暂无数据"
    >
      <el-table-column
        prop="bank_name"
        label="银行名称"
        align="center"
      ></el-table-column>
      <el-table-column
        prop="open_bank"
        label="开户行"
        align="center"
      ></el-table-column>
      <el-table-column
        prop="account"
        label="卡号"
        align="center"
      ></el-table-column>
      <el-table-column
        prop="account_name"
        label="户名"
        align="center"
      ></el-table-column>
      <el-table-column
        prop="area_name"
        label="区域"
        align="center"
      ></el-table-column>
      <el-table-column label="操作" width="400" align="center">
        <template slot-scope="scope">
          <el-button
            size="mini"
            icon="el-icon-edit"
            type="primary"
            @click="handleEdit(scope)"
            >编辑</el-button
          >
         
          <el-button
            size="mini"
            icon="el-icon-circle-plus"
            type="primary"
            @click="addSuppliers(scope)"
            >绑定供应商类别</el-button
          >
          <el-button
            size="mini"
            type="danger"
            icon="el-icon-delete"
            @click="handleDelete(scope)"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页 -->
    <pagination
      @page="handleSizeChange"
      @pagesize="handleCurrentChange"
      :pageData="pageData"
    ></pagination>
    <!-- Dailog -->
    <bankDialog
      @upData="getData"
      :formData="formData"
      :dialog="dialog"
    ></bankDialog>
    <bindingSuppliersDialog :dialog="suppliersDialog"></bindingSuppliersDialog>
  </div>
</template>
<script>
import Pagination from "@/components/pagination";
import { selectBankList, delBankInfo } from "@/api/superSettlement/bankList";
import BankDialog from "@/components/superSettlement/bankDialog";
import BindingSuppliersDialog from "@/components/superSettlement/bindingSuppliersDialog";
export default {
  components: {
    pagination: Pagination,
    bankDialog: BankDialog,
    bindingSuppliersDialog: BindingSuppliersDialog
  },
  data() {
    return {
      //页面数据
      tableData: [],
      //分页
      pageData: {
        pageSizes: [10, 20],
        pageSize: 10,
        page: 1,
        total: null,
        layout: "total, sizes, prev, pager, next, jumper",
      },
      //dialog信息
      dialog: {
        centerDialogVisible: false,
        dialogType: "",
        id: "",
      },
       //dialog信息
       suppliersDialog: {
        centerDialogVisible: false,
        account: ""
      },
      formData: {},
      search: {
        bank_name: "",
        account: "",
        area: "",
      },
    };
  },

  created() {
    //页面数据
    this.getData();
  },
  methods: {
    //页面数据
    getData() {
      let data = {
        limit: this.pageData.pageSize,
        page: this.pageData.page,
        bank_name: this.search.bank_name,
        account: this.search.account,
        area: this.search.area,
      };
      selectBankList(data)
        .then((res) => {
          if (res.code == 0) {
            this.tableData = res.data.data;
            this.pageData.page = res.data.current_page;
            this.pageData.pagesize = res.data.per_page;
            this.pageData.total = res.data.total;
          }
        })
        .catch((err) => {
          console.log(err);
        });
    },
    //添加
    addBank() {
      this.dialog.centerDialogVisible = true;
      this.dialog.dialogType = "";
      this.formData = {
        bank_name: "",
        open_bank: "",
        account: "",
        account_name: "",
        area_name: "",
        way: false,
        online: "",
         bank_province:'',
        province_code:''
      };
    },
    //修改
    handleEdit(scope) {
      this.dialog.centerDialogVisible = true;
      this.dialog.dialogType = "edit";
      this.formData = {
        bank_name: scope.row.bank_name,
        open_bank: scope.row.open_bank,
        account: scope.row.account,
        account_name: scope.row.account_name,
        area_name: scope.row.area_name,
      };
      this.dialog.id = scope.row.id;
    },
    //绑定供应商
    addSuppliers(scope) {
      this.suppliersDialog.centerDialogVisible = true;
      this.suppliersDialog.account = scope.row.account;
    },
   
    // 搜索
    handleSearch() {
      this.pageData.page = 1;
      this.pageData.total = null;
      this.getData();
    },
    //删除
    handleDelete(scope) {
      let data = {
        id: scope.row.id,
      };
      console.log(scope);
      this.$confirm("是否删除该银行账号?", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          delBankInfo(data).then((res) => {
            if (res.code == 0) {
              this.getData();
              this.$message({
                type: "success",
                message: res.msg || res.message,
              });
            }
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },
    //清空
    empty() {
      this.search = {
        bank_name: "",
        account: "",
        area: "",
      };
    },
    //每页多少条
    handleCurrentChange(val) {
      this.pageData.page = 1;
      this.pageData.pageSize = val;
      this.getData();
    },
    //选取页数
    handleSizeChange(page) {
      this.pageData.page = page;
      this.getData();
    },
    //选取
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
  },
};
</script>
<style scoped>
.top {
  position: relative;
}

.add {
  position: absolute;
  right: 0;
  top: 4px;
}
.pagination {
  text-align: right;
  padding: 10px;
}
</style>